// ==UserScript== // @name 修改 Yandex 搜索引擎的 cookie // @namespace https://scriptcat.org/zh-CN/users/157252 // @author deepseek // @version 1.2 // @icon https://yastatic.net/s3/home-static/_/nova/CKig_nVR.png // @description 自用脚本,为 Yandex 搜索选择性地注入 Cookie。 // @match http*://yandex.*/search/* // @run-at document-start // @license MIT // @grant none // ==/UserScript== (function() { 'use strict'; // 要注入的特定 Cookie 项目 const cookieEntries = { 'receive-cookie-deprecation': '1', 'gpb': 'yandex_gid.90#ygo.84%3A90#ygu.0', 'yandex_gid': '90', 'KIykI': '1', 'is_gdpr': '0', 'is_gdpr_b': 'CI2uORC1sQIoAg==', 'yp': '1742326362.sz.904x407x3#1756341914.szm.3:904x407:407x904#1758515894.ygu.0#1758515894.ygo.84:90#2055783435.pcs.1#1745523716.atds.1#1743252325.csc.1#1758515915.sp.family:0' }; // 获取当前域名信息 const currentDomain = window.location.hostname; const domainParts = currentDomain.split('.'); const parentDomain = domainParts.slice(-2).join('.'); const dynamicDomain = `.${parentDomain}`; // 获取当前的 cookie const currentCookies = Object.fromEntries( document.cookie.split(';') .map(cookie => cookie.trim().split(/=(.*)/, 2)) .filter(([name]) => name) ); // 只更新指定的 cookie 项目,保留其他现有 cookie Object.entries(cookieEntries).forEach(([name, value]) => { const isSecure = window.location.protocol === 'https:'; document.cookie = `${name}=${value}; domain=${dynamicDomain}; path=/; secure=${isSecure}`; }); // 调试用:输出更新后的 cookie console.log('Updated cookies:', document.cookie); })();